<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>属性验证</title>
</head>
<body>
  <script>
    const target = {
      onlyNumbersGoHere: 0
    };

    const proxy = new Proxy(target, {
      set(target, property, value) {
        if (typeof value !== 'number') {
          return false;
        } else {
          return Reflect.set(...arguments);
        }
      }
    });

    proxy.onlyNumbersGoHere = 1;
    console.log(proxy.onlyNumbersGoHere);  // 1
    proxy.onlyNumbersGoHere = '2';
    console.log(proxy.onlyNumbersGoHere);  // 1
  </script>
</body>
</html>